﻿<?php
include 'PublicdetailController.php';
class GiaphongController extends PublicdetailController {
	private $_MGiaphong;
	private $_Manggias;
	
public function init() {
		     $this->initValue ();
		     $this->_MGiaphong = new Model_Giaphong();
			 $manggia = array(
			 'gio1' => @$_REQUEST ['gio1'],
			 'gio2' => @$_REQUEST ['gio2'],
			 'gio3' => @$_REQUEST ['gio3'],
			 'gio4' => @$_REQUEST ['gio4'],
			 'gio5' => @$_REQUEST ['gio5'],
			 'gio6' => @$_REQUEST ['gio6'],
			 'ngay1' => @$_REQUEST ['ngay1'],
			 'ngay2' => @$_REQUEST ['ngay2'],
			 'ngay3' => @$_REQUEST ['ngay3'],
			 'ngay4' => @$_REQUEST ['ngay4'],
			 'ngay5' => @$_REQUEST ['ngay5'],
			 'ngay6' => @$_REQUEST ['ngay6'],
			 'tuan1' => @$_REQUEST ['tuan1'],
			 'tuan2' => @$_REQUEST ['tuan2'],
			 'tuan3' => @$_REQUEST ['tuan3'],
			 'thang' => @$_REQUEST ['thang'],
			 'nam' => @$_REQUEST ['nam'],
			 );
	        $obj = json_encode($manggia);
			$this->_Manggias = array (
				'id' => @$_REQUEST ['id'],			
				'priceParams' => $obj
			);
		}

    public function indexAction() {
    

      } 
    public function jsonAction() {
	    $id = $this->_getParam ( 'id' );
		$this->_helper->layout ()->disableLayout ();
		$jsonObj = $this->_MGiaphong->getItems($id);
        //$jsonObj[0]['priceParams'];
		echo json_encode($jsonObj);
		die;
		return $this->view->items =  $jsonObj[0]['priceParams'];
		
	}	  
	public function addAction() {  	
		$this->_helper->layout ()->disableLayout ();
		$this->_MGiaphong->add( $this->_Manggias  );
		return $this->view->items = json_encode ( $this->_Manggias );
	}
	
	public function updateAction() { 
        $id = $this->_getParam ( 'id' );		
		$this->_helper->layout ()->disableLayout ();
		if($id){
			$this->_MGiaphong->update( $id, $this->_Manggias );
		}
		return $this->view->items = json_encode ( $this->_Manggias );
		
	}
	
	public function delAction() {
		$this->_helper->layout ()->disableLayout ();
		$id = @$_REQUEST ['id'];
		// $id = $this->_getParam ( 'id' );
		$_Id = null;
		$jsonObjv = null;
		
		if (isset ( $id ) && $id > 0) {
			$_Id = $this->_MGiaphong->del ( $id );
		} else {
			return;
		}
		
		if (! $_Id) {
			$jsonObj = json_encode ( array (
					'success' => false 
			) );
		} else {
			$jsonObj = json_encode ( array (
					'success' => true 
			) );
		}
		return $this->view->items = $jsonObj;
	}
	public function preDispatch() {
		$auth = Zend_Auth::getInstance ();
		if (! $auth->hasIdentity ()) {
			if ($this->_request->getActionName () != 'login') {
				$this->_redirect ( '/index/login' );
			}
		}
	}
	
}